<?php
class CuisinesController extends AppController {

	var $name = 'Cuisines';
	var $components = array('RequestHandler');
	var $uses = array('Album','Cuisine');

	var $paginate = array(
			  'conditions' => array('Cuisine.is_active' => 1),
			  'limit' => 7,
			  'order' => array(
				'Cuisine.id' => 'desc'
				)
			  );  

	function index () {
		
		$data = $this->paginate('Cuisine');
		//pr($data);die();
		$this->set('data', $data);
		
	}
		

	function previewAlbum() {
		
		if ($this->RequestHandler->isAjax()) {
			
			$cuisine_id = $this->params['url']['cuisines'];
			$options = array(
				'conditions' => array('Album.cuisine_id' => $cuisine_id),
				'limit' => 4,
				'order' => 'RAND()'
			);
			
			$data = $this->Album->find('all',$options);
			
			if ($data) {
				
				$content = '<ul>';
				foreach ($data as $items) {
					$imgsrc = HOSTNAME.'/thumbs/?src=/app/webroot/img/albums/'.$items['Album']['path'].'&w=76&h=66&zc=1&q=100';
					$content .= '<li><a title="'.$items['Album']['title'].'" href="'.HOSTNAME.'/albums/category/'.$items['Album']['id'].'"><img src="'.$imgsrc.'" /></a></li>';
				}
				$content .= '</ul>';
				
				echo $content;
			}else {
				echo '<div class="no_preview">No Preview Available. Please come back later.</div>';
			}
		}
		
		die(); 
	}

	function featured () {
		
	}
	

/*
 DISH COUNTER
*/
	function dishCount() {

		if ($this->RequestHandler->isAjax()) {
			
			$cuisine_id = $this->params['url']['cuisines'];
			$options = array(
				'conditions' => array('Album.cuisine_id' => $cuisine_id),
			);
			
			$data = $this->Album->find('count',$options);

			pr($data);

		}

		die;

		
	}

/*
 DISH LISTS
*/
	function listsDish() {

		if ($this->RequestHandler->isAjax()) {
			
			$cuisine_id = $this->params['url']['cuisines'];
			$options = array(
				'conditions' => array('Album.cuisine_id' => $cuisine_id),
			);
			
			$title = $this->Cuisine->find('first',array(
				'conditions' => array('Cuisine.id' => $cuisine_id),
				'fields'=>array('id','title')));
			$data = $this->Album->find('list',$options);

			if ($data) {
				$content = '<div class="divlist">
				<h2>'.$title['Cuisine']['title'].' CUISINES</h2>
				<div class="div_dish_list">
				<ul>';
				$ctr = 1;
				foreach ($data as $keys => $items) {
					$urlpath = HOSTNAME.'/albums/category/'.$keys;
					$content .= '
						<li>
							
							<a href="'.$urlpath.'">'.$ctr.'. '.$items.'</a>
						</li>
					
					';
					$ctr++;
				}
				
				$content .= '</ul></div>
				
					<div class="request_dish">
						<p><strong>WHAT!?</strong> You favorite dish is not on the lists? Thats is terrible! <a href="#">Submit a request</a> then! We all must exercise our rights! </p>
					</div>

				</div>';
				$content .= '<div class="divlist divlists2"><h2>Featured</h2>
								<div>
								<img src="'.HOSTNAME.'/thumbs/?src=/app/webroot/img/cuisines/thai.jpg&w=300&zc=1&q=100" width=320px/>
								<p style="background:#000;padding:5px; color:#fff">Master Wooki Chef</p>
								</div>
							</div>
							<div class="clearfix">&nbsp;</div>
							';
			}else {
				$content = 'NOT AVAILABLE.';
			}
			
			echo $content;

		}

		die;

		
	}


/*
	DISH COUNT MAINTAINANCE!!!!!
	WARNING!!! ONLY LOADED BY ADMIN
*/

	function countthedish() {
		
		$data = $this->Cuisine->find('list');
		pr($data);
		foreach ($data as $keys => $item) {
			$conditions = array('conditions'=>array('Album.cuisine_id'=>$keys));
			$dish_count = $this->Album->find('count',$conditions);
			pr($dish_count);
			
			$this->Cuisine->id = $keys;
			$this->Cuisine->saveField('album_count',$dish_count);
			
		}
		//die();
		
	}

}
?>